package com.wb.oldwomen;

import android.view.MotionEvent;
import android.widget.Toast;

import com.wb.fw.GateActivity;
import com.wb.fw.Global;
import com.wb.fw.IConstants;
import com.wb.fw.SoundManager;
import com.wb.fw.Util;
import com.wiyun.engine.nodes.Button;
import com.wiyun.engine.nodes.ColorLayer;
import com.wiyun.engine.nodes.Label;
import com.wiyun.engine.nodes.Sprite;
import com.wiyun.engine.types.WYColor3B;
import com.wiyun.engine.types.WYColor4B;

public class UILevelConfirm extends ColorLayer implements Ioldwomam {
	public static UILevelConfirm make(GameScene parent) {
		return new UILevelConfirm(parent, WYColor4B.make(0, 0, 0, 127));
	}
	GameScene mparent;
	protected UILevelConfirm(GameScene parent, WYColor4B color) {
		super(color);
		
		mparent = parent;
		setKeyEnabled(true);
		setTouchEnabled(true);
		
		////////////
		mpanel = Sprite.make(R.drawable.panle_start);
		mpanel.setPosition(Global.sWYSize.width/2, Global.sWYSize.height/2);
		mpanel.setScale(Global.sScaleRate);
		mpanel.autoRelease();
		addChild(mpanel);
		
		//////////////////
		mscore = Label.make("", 30);
		mscore.autoRelease();
		mscore.setScale(Global.sScaleRate);
		mscore.setAnchor(0, 0.5f);
		mscore.setPosition(Global.sWYSize.width/2+(210-325/2)*Global.sScaleRate, Global.sWYSize.height/2+(315/2-125)*Global.sScaleRate);
		mscore.setColor(WYColor3B.make(255, 255, 255));
		addChild(mscore);
		
		mtitle = Label.make("", 30);
		mtitle.autoRelease();
		mtitle.setScale(Global.sScaleRate);
		mtitle.setPosition(Global.sWYSize.width/2, Global.sWYSize.height/2+(315/2-54)*Global.sScaleRate);
		mtitle.setColor(WYColor3B.make(0, 0, 0));
		addChild(mtitle);
		
		mstart = Button.make(R.drawable.start_n, R.drawable.start_p, this, "xlStart");
		mstart.autoRelease();
		mstart.setPosition(Global.sWYSize.width/2, Global.sWYSize.height/2 - (217-315/2)*Global.sScaleRate);
		mstart.setScale(Global.sScaleRate);
		addChild(mstart);
		
		Button btnJump = Button.make(R.drawable.startjump_n, R.drawable.startjump_p, this, "xlJump");
		btnJump.autoRelease();
		btnJump.setScale(Global.sScaleRate);
		btnJump.setPosition(Global.sWYSize.width/2, Global.sWYSize.height/2+(315/2-125)*Global.sScaleRate);
		addChild(btnJump);
	}
	
	Button mstart;
	Label mscore, mtitle;
	Sprite mpanel;
	
	public void setConfirmData() {
		mscore.setText(Integer.toString(UNLOCK_GOLD));
		mtitle.setText(sTitle[mparent.getCurLevel()]);
	}
	
	public void xlStart() {
		SoundManager.clickMenuItem();
		mparent.switchState(GS_GAME_RUNNING);
	}
	
	public void xlJump() {
		SoundManager.clickMenuItem();
		int total = Util.getGold(GateActivity.sInstance);
		if (total >= UNLOCK_GOLD) {
			Util.saveGold(GateActivity.sInstance, total - UNLOCK_GOLD);
			mparent.unlockNext();
			mparent.switchState(GS_GAME_LEVEL_SELECT);
		} else {
			GateActivity.sInstance.runOnUiThread(new Runnable() {
				@Override
				public void run() {
					Toast.makeText(GateActivity.sInstance, "金币不够。", Toast.LENGTH_SHORT).show();					
				}
			});
		}
		
	}

	@Override
	protected boolean onBackButton() {
		if (isVisible()) {
			mparent.switchState(GS_GAME_LEVEL_SELECT);
		}
		return true;
	}

	@Override
	public boolean wyTouchesBegan(MotionEvent event) {
		return true;
	}
	
	
}
